<?php

namespace App\Library\Service;

use App\Library\Logic\VersionLogic;
use App\Library\Requests\Version\VersionAddRequest;
use Illuminate\Http\JsonResponse;

class VersionService extends BaseService
{
    /**
     * desc
     *
     * @return VersionLogic
     */
    private function logic(): VersionLogic
    {
        if (empty($this->logic)) $this->logic = new VersionLogic;
        return $this->logic;
    }

    public function add(VersionAddRequest $request): JsonResponse
    {
        $this->logic()->insert([
            'serial_number' => serialNumber(),
            'no' => $request->no,
            'name' => $request->name
        ]);
        return success();
    }

    /**
     *
     * @return JsonResponse
     *
     */
    public function info(): JsonResponse
    {
        return success($this->logic()->query()->orderByDesc('id')->get());
    }
}
